<template>
  <div class="app-container">
    <div
      style="color:#999;margin-bottom:10px;font-size:12px"
    >仅当交易类型单选"红利（包括加币-计入红利）"、"加币-不计红利"、"减币时，可选择细分类型"</div>
    <el-form :inline="true" :model="formInline" ref="formInline" class="demo-form-inline">
      <el-form-item label="交易类型" prop="orderType">
        <el-select
          @change="handlechange"
          :collapse-tags="true"
          :style="{width: '230px'}"
          v-model="formInline.orderType"
          multiple
          placeholder="请选择交易类型"
        >
          <template v-for="item in consts.AGENCY_ORDER_TYPE_DETAIL">
            <el-option
              :label="item.title"
              :key="item.value"
              :value="item.value"
            >
            {{item.title}}
            </el-option>
          </template>
        </el-select>
      </el-form-item>

      <el-form-item label="细分类型" prop="childType">
        <el-select
          :disabled="subMenu.length<1"
          v-model="formInline.subType"
          :collapse-tags="true"
          width="100%"
          multiple
          placeholder="请选择细分类型"
        >
          <el-option
            v-for="item in subMenu"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <el-select
          :collapse-tags="true"
          v-model="formInline.status"
          width="100%"
          placeholder="请选择状态"
        >
          <el-option
            v-for="item in statusList"
            :label="item.lable"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="查询时间" prop="time">
        <el-date-picker
          v-model="formInline.time"
          type="datetimerange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          :picker-options="pickerDayStep"
        ></el-date-picker>
      </el-form-item>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
      <el-button
        v-if="roleCheck('export-trade-info')"
        type="primary"
        size="mini"
        icon="el-icon-download"
        @click="_exportExcel"
      >导出</el-button>
      <el-button @click="cancel('formInline')">重置</el-button>
    </el-form>
  </div>
</template>

<script>
import { form, pickerOption } from '@/build';

export default {
  name: 'form-filter',
  mixins: [form, pickerOption],
  data() {
    return {
      statusList: [
        { lable: '全部', value: -1 },
        { lable: '处理中', value: 0 },
        { lable: '失败', value: 2 },
        { lable: '成功', value: 1 },
      ],
      type: null,
      subMenu: [],
      formInline: {
        orderType: [2],
        time: [moment().startOf('month').format('YYYY-MM-DD 00:00:00'), moment().format('YYYY-MM-DD 23:59:59')],
        status: -1, // 状态
        subType: [], // 细分类型
      },
    };
  },
  watch: {
    type(newVal) {
      this.formInline.childType = [];
    },
    formInline: {
      handler(newVal) {
        this.subMenu = [];
        if (Number(newVal.orderType) === 14 || Number(newVal.orderType) === 10) {
          this.subMenu = _.find(consts.AGENCY_ORDER_TYPE_DETAIL, { value: Number(newVal.orderType) }).children;
        }
      },
      deep: true,
    },
  },
  methods: {
    handlechange() {
      this.formInline.subType = [];
    },
    _exportExcel() {
      this.$emit('on-export', this.formInline);
    },
    handleFilter() {
      this.$emit('on-filter', this.formInline);
    },
    cancel(formName) {
      this.resetForm(formName);
      this.handleFilter();
    },
  },
};
</script>

<style lang="scss" scoped>
.with-pre-select {
  .el-input-group__prepend {
    .el-select {
      width: 80px;
    }
  }
}

.money-range {
  .el-input {
    width: 100px;
  }
}
</style>
